<template>
     房型名称:
     <input type="text" v-model="name" placeholder="请输入房型名称">
     状态:
     <select v-model="stat">
        <option :value="-1" checked>请选择</option>
        <option :value="0">启用</option>
        <option :value="1">禁用</option>
        
     </select>
     <input type="button" @click="show" value="查询">
 <table>
    <thead>
<tr>
    <td>房型名称</td>
    <td>房间号</td>
    <td>备注</td>
    <td>状态</td>
    <td>操作</td>
</tr>
    </thead>
    <tbody v-for="i in info">
        <tr>
    <td>{{ i.R_fangxin }}</td>
    <td>{{ i.R_Name }}</td>
    <td>{{ i.R_BeiZhu }}</td>
    <td>{{ i.R_Status?"上架":"下架" }}</td>
    <td>
        <input type="button" value="修改状态" @click="Stat(i.R_Id)">
        <input type="button" value="修改" @click="xiugai(i.R_Id)">
        <input type="button" value="删除" @click="shanchu(i.R_Id)">
       
    </td>
</tr>
    </tbody>
 </table>
</template>

<script setup lang="ts">
import {compile, onMounted, ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';

onMounted(()=>{
    show()
})
const name=ref("")
const stat=ref(-1)
const user=useRouter();

const info=ref([{
    "R_Id": 1,
    "R_fangxin": "",
    "R_Name": "",
    "R_Status": true,
    "R_BeiZhu": "",
    "R_Biblio": true
}])

const show=()=>{
axios.get("https://localhost:7285/api/Roomnumber/GetRoomNumbers",{
    params:{
        name:name.value,
        Status:stat.value
    }
})
.then(res=>{
    info.value=res.data
})
}

const Stat=(R_Id:number)=>{

    axios.put("https://localhost:7285/api/Roomnumber/UpdaStatus?id="+R_Id)
    .then(res=>{
        if(res.data>0){
            alert("修改状态成功");
            show()
        }else{
            alert("修改状态失败")
        }
    })
}
const shanchu=(R_Id:number)=>{
 if(confirm("确定要删除吗?")){
    return;
 }
    axios.put("https://localhost:7285/api/Roomnumber/Del?id="+R_Id)
    .then(res=>{
        if(res.data>0){
            alert("删除成功");
            show()
        }else{
            alert("删除失败")
        }
    })
}
const xiugai=(R_Id:number)=>{
    user.push({
        name:"UpdaNumber",
        params:{
            id:R_Id
        }
    })
}





</script>

<style scoped>

</style>